package org.bright.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.bright.entity.Employees;
import org.bright.entity.PageResult;
import org.bright.service.IEmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bright
 * @since 2024-12-09 10:12
 */
@RestController
@RequestMapping("/employees")
@Tag(name = "员工管理", description = "员工接口")
public class EmployeesController {
    @Autowired
    private IEmployeesService employeesService;
    @GetMapping
    @Operation(summary = "员工列表接口", description = "获取员工列表")
    @ApiResponses(value = {
                    @ApiResponse(responseCode = "2000", description = "获取成功"),
                    @ApiResponse(responseCode = "2001", description = "获取失败")
            }
    )
    public PageResult<Employees> getList(
            @Parameter(name = "empName,loginName", description = "搜索条件",required = true) Employees employees,
            @Parameter(name = "pageNum", description = "页码",required = true) Integer pageNum) {
        PageResult<Employees> employeesPageResult = employeesService.selectPage(pageNum, employees);
        return employeesPageResult;
    }




    @GetMapping("{id}")
    @Operation(summary = "获取用户信息接口", description = "通过id获取用户信息")
    public Employees getById( @PathVariable @Parameter(name = "id", description = "用户id",required = true) Integer id){
        Employees employees = employeesService.getById(id);
        return employees;
    }
    @PostMapping
    @Operation(summary = "新增用户信息接口", description = "新增用户")
    public boolean add(Employees employees){
        boolean save = employeesService.save(employees);
        return save;
    }
    @PutMapping
    @Operation(summary = "修改用户信息接口", description = "修改用户")
    public boolean update(Employees employees){
        boolean update = employeesService.updateById(employees);
        return update;
    }
    @DeleteMapping("{id}")
    @Operation(summary = "删除用户信息接口", description = "删除用户")
    public boolean delete(@PathVariable @Parameter(name = "id", description = "用户id",required = true) Integer id){

        boolean delete = employeesService.removeById(id);
        return delete;
    }
}
